<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>地址管理</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/city-picker.css" rel="stylesheet" type="text/css" />

<style type="text/css">
#tx {
	width: 280px;
}

#btn2 {
	width: 80px;
	height: 30px;
	border-radius: 4px;
}

#btn3 {
	margin-right: 10px;
}

</style>

<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
	$(function() {
		$(".del").click(function() {
			if (confirm("确定删除吗?") == true) {
				var href = $(this).attr("href");
				$(".todel").attr("action", href).submit();
				return false;
			} else {
				return false;
			}
		});
	});
</script>
</head>

<body>
<jsp:include page="nsearch.jsp"></jsp:include>
	<div>
		<form action="<%=request.getContextPath()%>/user/address_add"
			method="post" onsubmit="return base();">
			<table align="center" height="280px">
				<h3 align="center">新增收货地址</h3>
				<tr>
					<td>地址信息：</td>
					<td>
						<div id="distpicker">
							<div class="form-group">
								<div style="position: relative;">
									<input id="city-picker3" class="form-control" readonly type="text"  name="base" value="江苏省/常州市/溧阳市" data-toggle="city-picker">
								</div>
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td>详细信息：</td>
					<td>
						<textarea rows="3" cols="33" id="tx" name="place" required autofocus></textarea>
					</td>
				</tr>
				<tr>
					<td>收货人：</td>
					<td>
						<input type="text" id="tx" name="name" maxlength="5" placeholder="请输入收货人姓名" required autofocus />
					</td>
				</tr>
				<tr>
					<td>手机号码：</td>
					<td>
						<input type="text" pattern="1[345789]\d{9}$" id="tx" name="phone" placeholder="请输入手机号" required autofocus>
					</td>
				</tr>
				<tr>
					<td>是否设为默认地址：</td>
					<td>
						<input type="radio" name="status" value="0" />是
						<input type="radio" name="status" value="1" checked />否</td>
				</tr>

				<tr>
					<td></td>
					<td>
						<input type="submit" value="保存" id="btn2" />
					</td>
				</tr>
			</table>
		</form>
	</div>

	<br />
	<br />
	
	<div>
		<table align="center" bgcolor="" width="840" >
			<tr>
				<td align="center"><font color="crimson">默认地址！</font></td>
			</tr>
		</table>
		<table border="1" align="center" cellpadding="5" cellspacing="0">
			<tr bgcolor="aliceblue">
				<th width="80">收货人</th>
				<th width="150">所在地区</th>
				<th width="250">详细地址</th>
				<th width="100">电话</th>
				<th width="110">操作</th>
				<th width="70"></th>
			</tr>
			<c:forEach items="${defaultList }" var="address">
				<tr>
					<td align="center">${address.name }</td>
					<td align="center">${address.base }</td>
					<td align="center">${address.place }</td>
					<td align="center">${address.phone }</td>
					<td align="center">
						<input type="button" value="修改" id="btn3" onClick="window.location.href='<%=request.getContextPath() %>/user/${address.id }/addressEcho';" />
						<button id="btn3">
							<a href="<%=request.getContextPath() %>/user/${address.id}/del" class="del">删除</a>
						</button>
					</td>
					<td></td>
				</tr>
			</c:forEach>

		</table>
		<br>

		<table align="center" bgcolor="" width="840">
			<tr>
				<td align="center"><font color="crimson">已保存了${commomList.size() }条普通地址！</font></td>
			</tr>
		</table>
		<table border="1" align="center" cellpadding="5" cellspacing="0">
			<tr bgcolor="aliceblue">
				<th width="80">收货人</th>
				<th width="150">所在地区</th>
				<th width="250">详细地址</th>
				<th width="100">电话</th>
				<th width="110">操作</th>
				<th width="70"></th>
			</tr>
			<c:forEach items="${commomList }" var="address">
				<tr>
					<td align="center">${address.name }</td>
					<td align="center">${address.base }</td>
					<td align="center">${address.place }</td>
					<td align="center">${address.phone }</td>
					<td align="center">
						<input type="button" value="修改" id="btn3" onClick="window.location.href='<%=request.getContextPath() %>/user/${address.id }/addressEcho';" />
						<button id="btn3">
							<a href="<%=request.getContextPath() %>/user/${address.id}/del" class="del">删除</a>
						</button>
					</td>
					<td><input type="button" value="设为默认" onClick="window.location.href='<%=request.getContextPath() %>/user/${address.id }/setDefault';" /></td>
				</tr>
			</c:forEach>
		</table>
		<br>		
		<br>
	</div>
	<form action="" method="post" class="todel">
		<input type="hidden" name="_method" value="DELETE">
	</form>

	<script src="<%=request.getContextPath()%>/js/jquery.js"></script>
	<script src="<%=request.getContextPath()%>/js/bootstrap.js"></script>
	<script src="<%=request.getContextPath()%>/js/city-picker.data.js"></script>
	<script src="<%=request.getContextPath()%>/js/city-picker.js"></script>
	<script src="<%=request.getContextPath()%>/js/main.js"></script>
</body>

</html>